package com.tool4j.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.tool4j.entity.GenerateCodeLog;
import com.tool4j.entity.params.PageParams;
import com.tool4j.service.GenerateCodeLogService;
import com.tool4j.util.UserPermission;
import com.tool4j.util.http.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.server.ServerWebExchange;

import java.util.List;

/**
 * 代码生成记录
 *
 * @author Deng.WeiPing
 * @since 2025-08-26 13:54:16
 */
@RestController
@RequestMapping("/api/generateCodeLog")
public class GenerateCodeLogController {

    @Autowired
    private GenerateCodeLogService generateCodeLogService;

    /**
     * 分页查询
     *
     * @param params
     * @return
     */
    @PostMapping("/findPage")
    public Result<Page<GenerateCodeLog>> findPage(ServerWebExchange exchange, @RequestBody PageParams<GenerateCodeLog> params) {
        Page<GenerateCodeLog> result = generateCodeLogService.findPage(UserPermission.get(exchange).getUserId(), params);
        return Result.ok(result);
    }

    /**
     * 列表查询
     *
     * @param params
     * @return
     */
    @PostMapping("/findList")
    public Result<List<GenerateCodeLog>> findList(ServerWebExchange exchange, @RequestBody GenerateCodeLog params) {
        List<GenerateCodeLog> result = generateCodeLogService.findList(UserPermission.get(exchange).getUserId(), params);
        return Result.ok(result);
    }

    /**
     * 查询
     *
     * @param id
     * @return
     */
    @GetMapping("/{id}")
    public Result<GenerateCodeLog> findById(@PathVariable("id") Long id) {
        GenerateCodeLog generateCodeLog = generateCodeLogService.findById(id);
        return Result.ok(generateCodeLog);
    }

    /**
     * 删除
     *
     * @param id
     * @return
     */
    @DeleteMapping("/{id}")
    public Result<Integer> delete(@PathVariable("id") Long id) {
        int result = generateCodeLogService.delete(id);
        return Result.ok(result);
    }

}
